- /* sdfdcoss.cpp by K.Tsuru */
- // function ID 3209 DRADIX
- /***********************************************************
- cos(x) by series for |x| < pi/4
- if first != 0 calculate the value cos(x) , else cos(x) - 1.
- ************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
- static const char* func = "CosSeries";
- SDouble CosSeries(const SDouble& x, int first){
- SDouble sum, xsq, delta;
- ulong n = 3, den, mt = x.SlOpMaxValue();
-
- if(x.NetRdxExp() > 1) sum.SetError(sum.DOMAIN_ERR, func, 3209);
- xsq = x*x;
- delta = DsDiv(xsq, 2);
-
- if(first){
- sum = 1.0; sum.FixedPoint(0);
- sum -= delta;
- } else {
- sum = -delta;
- sum.FixedPoint(sum.RdxExp());
- }
-
- while(delta.Sign(3209)){// n(n+1) < x.SlOpMaxValue()
- den = n*(n+1);
- if(den >= mt) break;
- delta *= xsq;
- delta = DsDiv(delta, den);
- if(n & 2) sum += delta;
- else sum -= delta;
- n += 2;
- }
-
- while(delta.Sign(3209)){// n(n+1) >= x.SlOpMaxValue()
- if(n >= mt){
- sum.SetError(sum.NOT_CONVERGE, func, -3209);
- break;
- }
- delta *= xsq;
- delta = DsDiv(delta, n );
- delta = DsDiv(delta, n+1);
- if(n & 2) sum += delta;
- else sum -= delta;
- n += 2;
- }
-
- sum.PointFree();
- sum.Reform(3209);
- sum.upToTerm = n/2;
- return sum;
- }
sdfdcoss.cpp : last modifiled at 2017/09/07 15:09:42(1,297 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).